<%@ taglib uri="/WEB-INF/vectrics.tld" prefix="vectrics" %>
<%@ taglib uri="/WEB-INF/hexacta.tld" prefix="hexacta" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>

<%@ page import="org.vectrics.user.Person" %>
<%@ page import="org.vectrics.hibernate.*" %>
<%@ page import="java.util.*" %>
<%@page import="org.vectrics.company.CompanyPerson"%>
<%@page import="org.vectrics.recruiter.RecruitServiceLocator"%>
<%@page import="org.vectrics.employee.Employee"%>
<%
	String userId = request.getParameter("userId");
	if ((userId == null) || (userId.trim().length() == 0)) {
		userId = (String)request.getAttribute("userId");
	}
	if ((userId == null) || (userId.trim().length() == 0)) {
		userId = (String)request.getSession(true).getAttribute("userId");
	}
	if ((userId == null) || (userId.trim().length() == 0)) {
		userId = request.getParameter("id");
	}
	if ((userId == null) || (userId.trim().length() == 0)) {
		userId = request.getParameter("personId");
	}
	if ((userId == null) || (userId.trim().length() == 0)) {
		userId = (String)request.getAttribute("personId");
	}
	if ((userId != null) && (userId.equals("current"))) {
		userId = ThreadProperties.getPerson().getId().toString();
	}
	String personId = userId;
	if ((userId == null) || (userId.trim().length() == 0)) {
		throw new RuntimeException("User ID is blank or null");
	}
	
	String skillsEntryLink = request.getContextPath() + "/admin/jobs/candidate/index.do?id=" + userId;	
	
	boolean userCanChangePassword = ThreadProperties.getPerson().hasPrivilege("user.password.edit", ThreadProperties.getDomain());

	if (ThreadProperties.getPerson().getId().equals(new Long(personId))) {
		userCanChangePassword = true;
	}

	Date now = new Date();
	String candidateReportUrl = "/hrs-intranet/report/admin/candidate.pdf?report=candidate&personId="
			+ personId +
			"&time=" + now.getTime();
	
    String companyId = ThreadProperties.getDomain()
                              .getPrimaryCompany().getId().toString();
	
    boolean isEmployee;
    if(request.getAttribute("isEmployee")!=null){
    	isEmployee = (Boolean)request.getAttribute("isEmployee");
    }
    else{
        // Busco el empleado de la compania.
        Employee employee =  RecruitServiceLocator.getCompanyService().findEmployee(new Long(personId), new Long(companyId));
        isEmployee = (employee != null);
    }
    
    // Control para que si el nombre Usuario es nulo no le permita cambiar la password
    boolean isUsuario = false;
    if (personId != null) {
        User usuario = RecruitServiceLocator.getPersonService().findPersonById(new Long(personId)).getUser();
        isUsuario = (usuario != null); 
    }
    
    // Busco el id de company person  si es empleado
    String companyPersonId = "";
    if (isEmployee) {
    	companyPersonId = personId;
    }

%>

<%@page import="org.vectrics.user.User"%>

<table width="100%">
		<tr>
			<td valign="top">
				<vectrics:userSummary personId="<%=personId%>"/>
                <hexacta:employeeSummary personId="<%=personId%>" companyId="<%=companyId%>" />
                <br />
                <hexacta:AddCandidate personId="<%=personId%>" companyId="<%=companyId%>" permission="add_candidate_to_JO"/>
                <hexacta:AddInterview personId="<%=personId%>" companyId="<%=companyId%>" permission="add_candidate_to_JO"/>  
			</td>
			<td valign="top" align="right">
				<table cellpadding="0" cellspacing="0" width="100%">
	
	<!-- Botones visibles solo para Employee Manager -->
	
					<% if (!isEmployee) { %>
					
					<tr>
						<td>
							<form action="/hrs-intranet/admin/user/person/edit.do" method="POST">
								<input type="hidden" name="userId" value="<%=userId%>">
								<vectrics:formButton code="button.param" phraseCode="button.person.edit" value="submit" 
									elementId="person.edit.btn"
									name="submit" 
									permission="edit_candidate_details"
									/>
							</form>							
						</td>
					</tr>
					<% } %>
					
	<!-- Botones visibles solo para Candidate Manager -->
					
					<% if (isEmployee) { %>
					<tr>
						<td>
							<form action="/hrs-intranet/admin/user/person/edit.do" method="POST">
								<input type="hidden" name="userId" value="<%=userId%>">
								<vectrics:formButton code="button.param" phraseCode="button.person.edit" value="submit" 
									elementId="person.edit.btn"
									name="submit" 
									permission="manage_employee_information"
									
									/>
							</form>							
						</td>
					</tr>
					<tr>
						<td>
							<form action="/hrs-intranet/admin/user/employee/edit.do" method="POST">
								<input type="hidden" name="personId" value="<%=userId%>">
								<input type="hidden" name="companyId" value="<%=companyId%>"> 
								<vectrics:formButton code="button.param" phraseCode="button.employee.edit" value="submit" 
									elementId="person.edit.btn"
									name="submit" 
									permission="manage_employee_information"
									 />
							</form>
						</td>
					</tr>
					<tr>
						<td >
							<form action="/hrs-intranet/admin/user/edit.do" method="POST">
								<input type="hidden" name="userId" value="<%=userId%>">
								<vectrics:formButton 
										code="button.param" 
										phraseCode="button.user.edit" 
										value="submit" 
										elementId="person.edit.btn"
										name="submit"
										permission="manage_employee_information" />
							</form>
						</td>
					</tr>
					<% } %>

					
					<tr>
						<td><h2>Other Info</h2></td>
					</tr>
					
	<!-- Otros Botones visibles solo para Employee Manager -->
					
					<% if (isEmployee) { %>
					<tr>
						<td>
							<form action="/hrs-intranet/admin/employee/conditions.do" method="POST">
								<input type="hidden" name="personId" value="<%=userId%>">
								<vectrics:formButton code="button.param" 
									phraseCode="button.person.hiring.conditions" 
									elementId="person.hiring.conditions.btn"
									value="submit" 
									name="submit"
									permission="manage_employee_information"/>
							</form>
						</td>
					</tr>
					<tr>
						<td>
							<form action="/hrs-intranet/hrs2/TimeOffEmployeeAction_list.action" method="POST">
								<input type="hidden" name="requestId" value="<%=new Long(personId)%>">
								<vectrics:formButton code="button.param" 
									phraseCode="button.person.timeoff.list" 
									elementId="person.timeoff.list.btn"
									value="submit" 
									name="submit"
									permission="people_timeoff"/>
							</form>
						</td>
					</tr>
					<tr>
						<td>
							<form action="/hrs-intranet/hrs2/FamiliarRelationshipAction_list.action" method="POST">
								<input type="hidden" name="personId" value="<%=new Long(personId)%>">
								<vectrics:formButton code="button.param" 
									phraseCode="button.person.familiarRelationShip.list" 
									elementId="person.timeoff.familiarRelationShip.btn"
									value="submit" 
									name="submit"
									permission="people_relatives"/>
							</form>
						</td>
					</tr>
					<tr>
						<td>
							<form action="/hrs-intranet/admin/user/resume/list.do" method="POST">
								<input type="hidden" name="userId" value="<%=userId%>">
								<vectrics:formButton 
									code="button.param" 
									phraseCode="button.person.resumes" 
									elementId="person.resume.list.btn"
									value="submit" 
									name="submit"
									permission="view_employees_items"
									/>
							</form>
						</td>
					</tr>
					<tr>
						<td>
							<form action="/hrs-intranet/admin/user/interview/list.do" method="POST">
								<input type="hidden" name="personId" value="<%=userId%>">
								<vectrics:formButton 
									code="button.param" 
									elementId="person.interview.list.btn"
									phraseCode="button.person.interviews" 
									value="submit" 
									name="submit"
									permission="view_employees_items"/>
							</form>
						</td>
					</tr>
					<tr>
						<td>
							<form action="/hrs-intranet/admin/user/eval/list.do" method="POST">
								<input type="hidden" name="userId" value="<%=userId%>">
								<vectrics:formButton code="button.param" phraseCode="button.person.evaluations" 
									elementId="person.eval.list.btn"
									value="submit" 
									name="submit"
									permission="view_employees_items"/>
							</form>
						</td>
					</tr>
					<tr>
						<td>
							<form action="/hrs-intranet/admin/user/encounter/list.do" method="POST">
								<input type="hidden" name="personId" value="<%=userId%>">
								<vectrics:formButton 
									code="button.param" 
									phraseCode="button.person.encounters" 
									elementId="person.encounter.list.btn"
									value="submit" 
									name="submit"
									permission="view_employees_items"/>
							</form>
						</td>
					</tr>
					<tr>
						<td>
							<form action="/hrs-intranet/admin/user/addCandidateJob.do" method="POST">
								<input type="hidden" name="userId" value="<%=userId%>">
								<vectrics:formButton 
									code="button.param" 
									phraseCode="button.person.candidate.info" 
									elementId="add.cand.job.btn"
									value="submit" 
									name="submit"
									permission="view_employee_JO_information"/>
							</form>
						</td>
					</tr>
					<tr>
						<td>
							<form action="<%=candidateReportUrl%>" method="POST">
								<input type="hidden" name="personId" value="<%=userId%>">
								<vectrics:formButton 
									code="button.param" 
									phraseCode="button.candidate.report" 
									value="submit" 
									elementId="cand.report.btn"
									name="submit"
									permission="view_employee_JO_information"/>
							</form>
						</td>
					</tr>
					<tr>
						<td>
							<form action="/hrs-intranet/admin/user/encounter/newPhoneCall.do" method="POST">
								<input type="hidden" name="personId" value="<%=userId%>">
								<vectrics:formButton 
									code="button.param" 
									phraseCode="button.person.new.phone" 
									elementId="person.new.call.btn"
									value="submit"    
									name="submit"
									permission="view_employees_items"/>
							</form>
						</td>
					</tr>
					<tr>
						<td>
							<form action="/hrs-intranet/admin/user/docs/list.do" method="POST">
								<input type="hidden" name="personId" value="<%=userId%>">
								<vectrics:formButton code="button.param" 
									phraseCode="button.person.documents" 
									elementId="person.doc.list.btn"
									value="submit" 
									name="submit"
									permission="view_employees_items"/>
							</form>
						</td>
					</tr>
					<% } %>
					
	<!-- Otros Botones visibles solo para Candidate Manager -->
					
					<% if (!isEmployee) { %>
					<tr>
						<td>
							<form action="/hrs-intranet/admin/user/resume/list.do" method="POST">
								<input type="hidden" name="userId" value="<%=userId%>">
								<vectrics:formButton 
									code="button.param" 
									phraseCode="button.person.resumes" 
									elementId="person.resume.list.btn"
									value="submit" 
									name="submit"
									permission="view_candidate_items"
									/>
							</form>
						</td>
					</tr>
					<tr>
						<td>
							<form action="/hrs-intranet/admin/user/interview/list.do" method="POST">
								<input type="hidden" name="personId" value="<%=userId%>">
								<vectrics:formButton 
									code="button.param" 
									elementId="person.interview.list.btn"
									phraseCode="button.person.interviews" 
									value="submit" 
									name="submit"
									permission="view_candidate_items"/>
							</form>
						</td>
					</tr>
					<tr>
						<td>
							<form action="/hrs-intranet/admin/user/eval/list.do" method="POST">
								<input type="hidden" name="userId" value="<%=userId%>">
								<vectrics:formButton code="button.param" phraseCode="button.person.evaluations" 
									elementId="person.eval.list.btn"
									value="submit" 
									name="submit"
									permission="view_candidate_items"/>
							</form>
						</td>
					</tr>
					<tr>
						<td>
							<form action="/hrs-intranet/admin/user/encounter/list.do" method="POST">
								<input type="hidden" name="personId" value="<%=userId%>">
								<vectrics:formButton 
									code="button.param" 
									phraseCode="button.person.encounters" 
									elementId="person.encounter.list.btn"
									value="submit" 
									name="submit"
									permission="view_candidate_items"/>
							</form>
						</td>
					</tr>
					<tr>
						<td>
							<form action="/hrs-intranet/admin/user/addCandidateJob.do" method="POST">
								<input type="hidden" name="userId" value="<%=userId%>">
								<vectrics:formButton 
									code="button.param" 
									phraseCode="button.person.candidate.info" 
									elementId="add.cand.job.btn"
									value="submit" 
									name="submit"
									permission="view_candidate_JO_information"/>
							</form>
						</td>
					</tr>
					<tr>
						<td>
							<form action="<%=candidateReportUrl%>" method="POST">
								<input type="hidden" name="personId" value="<%=userId%>">
								<vectrics:formButton 
									code="button.param" 
									phraseCode="button.candidate.report" 
									value="submit" 
									elementId="cand.report.btn"
									name="submit"
									permission="view_candidate_JO_information"/>
							</form>
						</td>
					</tr>
					<tr>
						<td>
							<form action="/hrs-intranet/admin/user/encounter/newPhoneCall.do" method="POST">
								<input type="hidden" name="personId" value="<%=userId%>">
								<vectrics:formButton 
									code="button.param" 
									phraseCode="button.person.new.phone" 
									elementId="person.new.call.btn"
									value="submit"    
									name="submit"
									permission="view_candidate_items"/>
							</form>
						</td>
					</tr>
					<tr>
						<td>
							<form action="/hrs-intranet/admin/user/docs/list.do" method="POST">
								<input type="hidden" name="personId" value="<%=userId%>">
								<vectrics:formButton code="button.param" 
									phraseCode="button.person.documents" 
									elementId="person.doc.list.btn"
									value="submit" 
									name="submit"
									permission="view_candidate_items"/>
							</form>
						</td>
					</tr>
					<% } %>
					
				</table>
			</td>
		</tr>
       <tr>
          <td align="center" valign="middle" colspan="2">
             
          </td>
       </tr>
	</table>


	<h3>Companies</h3>
	<vectrics:personCompaniesListTag personId="<%=userId%>" width="800"/>